﻿using AutoMapper;
using B.S.Ingredients.APIRead.Application.Command.ImmunityCommand;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.ImmunityCommandHandler
{
    public class ImmunitUpdateCommandHandler : IRequestHandler<ImmunitUpdateCommand, APIResult<int>>
    {
        public ImmunitUpdateCommandHandler(IBaseRepository<Immunity> ImmunityRepository,IMapper mapper)
        {
            this.ImmunityRepository = ImmunityRepository;
            Mapper = mapper;
        }

        public IBaseRepository<Immunity> ImmunityRepository { get; }
        public IMapper Mapper { get; }

        public async Task<APIResult<int>> Handle(ImmunitUpdateCommand request, CancellationToken cancellationToken)
        {
       
                var list= Mapper.Map<Immunity>(request);
                var elemet = await ImmunityRepository.Update(list);
                return new APIResult<int>
                {
                    Code = ResultCode.success,
                    Mag = "更新成功",
                    Data = elemet
                };
            
        }
    }
}
